#include "color.h"

using namespace PBVP;

const Color Color::COLOR_RED(1.0f, 0.0f, 0.0f, 1.0f);
const Color Color::COLOR_BLUE(0.0f, 0.0f, 1.0f, 1.0f);
const Color Color::COLOR_GREEN(0.0f, 1.0f, 0.0f, 1.0f);
const Color Color::COLOR_INDIAN_RED(0.8f, 0.36f, 0.36f, 1.0f);
const Color Color::COLOR_MAGENTA(1.0f, 0.0f, 1.0f, 1.0f);
const Color Color::COLOR_LIME_GREEN(0.2f, 0.8f, 0.2f, 1.0f);
const Color Color::COLOR_SLATE_GRAY(0.44f, 0.52f, 0.56f, 1.0f);
const Color Color::COLOR_SIENNA(0.63f, 0.32f, 0.20f, 1.0f);
const Color Color::COLOR_BLACK(0.0f, 0.0f, 0.0f, 1.0f);
const Color Color::COLOR_WHITE(1.0f, 1.0f, 1.0f, 1.0f);	

Color::Color(const QColor& qc)
{
	r = qc.red() / 255.0f;
	g = qc.green() / 255.0f;
	b = qc.blue() / 255.0f;
	a = qc.alpha() / 255.0f;
}

QColor Color::toQColor() const
{
	QColor qcolor(int(r*255), int(g*255), int(b*255), int(a*255));
	return qcolor;
}

void Color::toUChar4(unsigned char rgba[4])
{
	rgba[0] = (unsigned char)(r * 255);
	rgba[1] = (unsigned char)(g * 255);
	rgba[2] = (unsigned char)(b * 255);
	rgba[3] = (unsigned char)(a * 255);
}

Color Color::linterp(const Color& c1, const Color& c2, float alpha)
{
	Color c;
	c.r = c1.r * alpha + c2.r * (1-alpha);
	c.g = c1.g * alpha + c2.g * (1-alpha);
	c.b = c1.b * alpha + c2.b * (1-alpha);
	c.a = c1.a * alpha + c2.a * (1-alpha);

	return c;
}